Closed
Bug 1126552
Opened 10 years ago
Closed 10 years ago
Make nsTArray support range-based for loop
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
mozilla38
Tracking | Status | |
---|---|---|
firefox38 | --- | fixed |
People
(Reporter: xidorn, Assigned: xidorn)
References
Details
Attachments
(3 files, 2 obsolete files)
2.85 KB,
patch
|
Details | Diff | Splinter Review | |
2.02 KB,
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
5.53 KB,
patch
|
froydnj
:
review+
|
Details | Diff | Splinter Review |
We have been allowed to use range-based for loop in our codebase, but as the most widely-used array type, nsTArray, does not support such thing, we cannot use it in most places. We need to support it.
I think the simplest way is to add begin() and end() methods to nsTArray_Impl.
Assignee | ||
Comment 1•10 years ago
|
||
Attachment #8555529 -
Flags: review?(nfroyd)
Assignee | ||
Comment 2•10 years ago
|
||
![]() |
||
Comment 3•10 years ago
|
||
Comment on attachment 8555529 [details] [diff] [review]
patch
Review of attachment 8555529 [details] [diff] [review]:
-----------------------------------------------------------------
::: xpcom/glue/nsTArray.h
@@ +990,5 @@
> {
> return SafeElementAt(Length() - 1, aDef);
> }
>
> + // Methods for "range-based for loop"
Nit on the phrasing: "Methods for range-based for loops." (Trailing period included in the comment.)
Attachment #8555529 -
Flags: review?(nfroyd) → review+
Assignee | ||
Comment 4•10 years ago
|
||
I guess it would be better to have a typedef for the iterator.
Assignee: nobody → quanxunzhen
Attachment #8555529 -
Attachment is obsolete: true
Attachment #8556093 -
Flags: review?(nfroyd)
Assignee | ||
Comment 5•10 years ago
|
||
Attachment #8556093 -
Attachment is obsolete: true
Attachment #8556093 -
Flags: review?(nfroyd)
Attachment #8556105 -
Flags: review?(nfroyd)
![]() |
||
Updated•10 years ago
|
Attachment #8556105 -
Flags: review?(nfroyd) → review+
Assignee | ||
Comment 6•10 years ago
|
||
This patch is for avoiding warnings like https://treeherder.mozilla.org/logviewer.html#?job_id=4644032&repo=try
Attachment #8558304 -
Flags: review?(nfroyd)
Assignee | ||
Comment 7•10 years ago
|
||
![]() |
||
Comment 8•10 years ago
|
||
Comment on attachment 8558304 [details] [diff] [review]
patch 0 - avoid shadow warnings
Review of attachment 8558304 [details] [diff] [review]:
-----------------------------------------------------------------
Sigh, -Wshadow.
::: xpcom/glue/nsTArray.h
@@ +1026,5 @@
> template<class Item, class Comparator>
> index_type IndexOf(const Item& aItem, index_type aStart,
> const Comparator& aComp) const
> {
> + const elem_type* iter = Elements() + aStart, *iend = Elements() + Length();
While you're here, would you mind splitting these up:
const elem_type* iter = ...;
const elem_type* iend = ...;
Or I suppose you could declare them as:
const_iterator iter = ..., iend = ...;
Whichever one you like. If you wanted to open a separate bug for cleaning the declarations up, that'd be OK too.
@@ +1059,5 @@
> index_type LastIndexOf(const Item& aItem, index_type aStart,
> const Comparator& aComp) const
> {
> size_type endOffset = aStart >= Length() ? Length() : aStart + 1;
> + const elem_type* iend = Elements() - 1, *iter = iend + endOffset;
Likewise.
@@ +1540,5 @@
> return nullptr;
> }
>
> // Initialize the extra array elements
> + elem_type* iter = Elements() + aIndex, *iend = iter + aCount;
Likewise.
@@ +1565,5 @@
> return nullptr;
> }
>
> // Initialize the extra array elements
> + elem_type* iter = Elements() + aIndex, *iend = iter + aCount;
Likewise.
@@ +1695,5 @@
> // @param aStart The index of the first element to destroy.
> // @param aCount The number of elements to destroy.
> void DestructRange(index_type aStart, size_type aCount)
> {
> + elem_type* iter = Elements() + aStart, *iend = iter + aCount;
Likewise.
Attachment #8558304 -
Flags: review?(nfroyd) → review+
Assignee | ||
Comment 9•10 years ago
|
||
Assignee | ||
Comment 10•10 years ago
|
||
Comment 11•10 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/28dadab99ddf
https://hg.mozilla.org/mozilla-central/rev/6786f92cb4d6
Status: NEW → RESOLVED
Closed: 10 years ago
status-firefox38:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla38
You need to log in
before you can comment on or make changes to this bug.
Description
•